window.MapObjects = {
  Person: (person, position, force=false) ->
    unless force
      for user in Me.friends
        if user.id == person.id
          return null
    this.id = person.id || null
    this.description = person.description || null
    this.image = person.image || null
    this.location = person.location || null
    this.name = person.name || null
    this.screen_name = person.screen_name || null
    this.website = person.website || null
    this.latitude = position.latitude || 0
    this.longitude = position.longitude || 0
    this.marker = null
    this.createMarker()
    return this
}

MapObjects.Person.prototype.destroy = ->
  this.destroyMarker()
  Me.friends.splice( Me.friends.indexOf(this), 1 )

MapObjects.Person.prototype.destroyMarker = ->
  this.marker.setMap(null)

MapObjects.Person.prototype.createMarker = ->
  markerOptions = {
    animation: google.maps.Animation.DROP,
    map: Map.map,
    icon: new google.maps.MarkerImage( this.image, null, null, null, new google.maps.Size(30,30) ),
    position: new google.maps.LatLng( this.latitude, this.longitude )
  }
  for user in Me.friends
    if user.id == this.id
      return null
  return this.marker = new google.maps.Marker( markerOptions )

MapObjects.Person.prototype.moveMarker = ( latitude, longitude ) ->
  #console.log "moved from:"
  #console.log this.latitude
  #console.log this.longitude
  this.latitude = latitude
  this.longitude = longitude
  this.marker.setPosition( new google.maps.LatLng( this.latitude, this.longitude ) )
  #console.log "moved to:"
  #console.log latitude
  #console.log longitude
  #window.alert('Moved')